package com.springmvc.web.app.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.springmvc.utils.result.ResultMsg;
import com.springmvc.web.majiang.entity.User;
import com.springmvc.web.majiang.service.IUserService;

/**
 * 
 * @ClassName: LoginController 
 * @author wangruchao
 * @date 2017年12月11日 上午11:52:40
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Controller
@RequestMapping("/app")
public class AppLoginController {

	@Autowired
	IUserService userService;

	@RequestMapping("/login")
	@ResponseBody
	public ResultMsg login(@RequestParam("username") String username, @RequestParam("password") String password) {
		Wrapper<User> wrapper = new EntityWrapper<User>();
		wrapper.eq("username", username);
		User user = userService.selectOne(wrapper);
		if (user == null) {
			System.err.println("用户不存在");
		}
		if (!StringUtils.equalsIgnoreCase(password, user.getPassword())) {
			System.err.println("密码错误");
		}
		return ResultMsg.SUCCESS(1, user);
	}

}
